﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LIMS.Entities;
using LIMS.DataAccess;
using System.Collections;
using System.Reflection;
using Castle.Core.Logging;
using NHibernate.Criterion;

namespace LIMS.Service
{
    public class UserTypePermissionService : IUserTypePermissionService
    {
        //Private DBA interfaces
        private IDaoFactory oDBFactory;
        private IUserTypePermissionDAO oUserTypePermissionDBA;
        private ILogger logger;

        //Constructor
        public UserTypePermissionService(IDaoFactory oDBOp, ILogger oLogger)
        {
            this.oDBFactory = oDBOp;
            this.oUserTypePermissionDBA = oDBFactory.GetUserTypePermissionDAO();
            this.logger = oLogger;
        }


        #region IUserTypePermissionService Members
        /// <summary>
        /// save audit trail
        /// </summary>
        /// <param name="oAuditTrail"></param>
        /// <returns></returns>
        public bool Save(UserTypePermission oUsertypePermission)
        {
            return oUserTypePermissionDBA.QuickSaveOrUpdate(ref oUsertypePermission);
        }
        /// <summary>
        /// Delete
        /// </summary>
        /// <param name="oUsertypePermission"></param>
        /// <returns></returns>
        public bool Delete(UserTypePermission oUsertypePermission)
        {
            return oUserTypePermissionDBA.Delete(oUsertypePermission);
        }

        public UserTypePermission GetAllRightsByUserTypeId(int iUserTypeId)
        {
            UserTypePermission oUserRights = new UserTypePermission();

            try
            {
                ICriterion oCriteriaUserTypeId = Expression.Eq("UserTypeId", iUserTypeId);
                oUserRights = oUserTypePermissionDBA.GetUniqueByCriteria(oCriteriaUserTypeId);
            }
            catch (Exception ex)
            {
                logger.Error("Error while getting user type rights.", ex);
                //    return null;
            }
            return oUserRights;
        }

        #endregion

 
    }
}
